<template>
  <div>
    <el-form-item label="默认值">
      <el-input v-model="data.value"
                placeholder="默认值"></el-input>
    </el-form-item>
    <el-form-item label="字典配置"><br>

    </el-form-item>
    <common-dict-config :data="data"/>

    <el-form-item label="边框">
      <el-switch v-model="data.border"></el-switch>
    </el-form-item>
    <el-form-item label="尺寸"
                  v-if="data.border">
      <el-radio-group v-model="data.size"
                      size="small">
        <el-radio-button value="default">正常</el-radio-button>
        <el-radio-button value="small">小</el-radio-button>
        <el-radio-button value="mini">超小</el-radio-button>
      </el-radio-group>
    </el-form-item>


  </div>
</template>

<script>
import Draggable from 'vuedraggable'
import CommonDictConfig from "components/form-design/config/commonDictConfig.vue";


export default {
  name: "config-radio",
  props: ['data'],
  components: {CommonDictConfig, Draggable},
  data() {
    return {
      validator: {
        type: null,
        required: null,
        pattern: null,
        length: null
      },
      option: {
        column: [{
          type: 'input',
          prop: 'key',
          label: 'key'
        }, {
          type: 'input',
          prop: 'value',
          label: 'value'
        }]
      },
    }
  },
  methods: {
    generateRule() {
      const rules = [];
      Object.keys(this.validator).forEach(key => {
        if (this.validator[key]) rules.push(this.validator[key])
      })
      this.data.rules = rules
    },
    handleRemoveFields(index) {
      this.data.dicData.splice(index, 1)
    },
    handleAddFields() {
      const i = Math.ceil(Math.random() * 99999)
      this.data.dicData.push({label: `字段${i}`, value: `col_${i}`})
    },
    handleTabClick({name}) {
      if (name == 'remote' && !this.data.dicQueryConfig) this.data.dicQueryConfig = []
    }
  },
  watch: {
    'data.required': function (val) {
      if (val) this.validator.required = {required: true, message: `请选择${this.data.label}`}
      else this.validator.required = null

      this.generateRule()
    }
  }
}
</script>
